home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet internetowy / Przegladarki internetowe / Mozilla Seamonkey 1.0.5 pl / seamonkey-1.0.5.pl-PL.win32.installer.exe / MAIL.XPI / bin / chrome / messenger.jar / content / messenger / searchWidgets.xml < prev    next >
Encoding:
Extensible Markup Language  |  2005-09-23  |  21.6 KB  |  519 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!-- ***** BEGIN LICENSE BLOCK *****
  4.    - Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.    -
  6.    - The contents of this file are subject to the Mozilla Public License Version
  7.    - 1.1 (the "License"); you may not use this file except in compliance with
  8.    - the License. You may obtain a copy of the License at
  9.    - http://www.mozilla.org/MPL/
  10.    -
  11.    - Software distributed under the License is distributed on an "AS IS" basis,
  12.    - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.    - for the specific language governing rights and limitations under the
  14.    - License.
  15.    -
  16.    - The Original Code is Filter Action Rules.
  17.    -
  18.    - The Initial Developer of the Original Code is
  19.    -    Scott MacGregor <mscott@mozilla.org>.
  20.    - Portions created by the Initial Developer are Copyright (C) 2005
  21.    - the Initial Developer. All Rights Reserved.
  22.    -
  23.    - Contributor(s):
  24.    -
  25.    - Alternatively, the contents of this file may be used under the terms of
  26.    - either the GNU General Public License Version 2 or later (the "GPL"), or
  27.    - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.    - in which case the provisions of the GPL or the LGPL are applicable instead
  29.    - of those above. If you wish to allow use of your version of this file only
  30.    - under the terms of either the GPL or the LGPL, and not to allow others to
  31.    - use your version of this file under the terms of the MPL, indicate your
  32.    - decision by deleting the provisions above and replace them with the notice
  33.    - and other provisions required by the LGPL or the GPL. If you do not delete
  34.    - the provisions above, a recipient may use your version of this file under
  35.    - the terms of any one of the MPL, the GPL or the LGPL.
  36.    -
  37.    - ***** END LICENSE BLOCK ***** -->
  38.  
  39. <!-- 
  40.   This file has the following external dependencies:
  41.       -gFilterActionStrings from FilterEditor.js
  42.       -gFilterList from FilterEditor.js
  43.       -gPromptService from FilterEditor.js
  44.       -gMessengerBundle from msgFolderPickerOverlay.js
  45.       -GetMsgFolderFromUri, SetFolderPickerElement from msgFolderPickerOverlay.js
  46. -->
  47.  
  48. <!DOCTYPE dialog [
  49.   <!ENTITY % filterEditorDTD SYSTEM "chrome://messenger/locale/FilterEditor.dtd" >
  50. %filterEditorDTD;
  51.   <!ENTITY % msgFolderPickerOverlayDTD SYSTEM "chrome://messenger/locale/msgFolderPickerOverlay.dtd" >
  52. %msgFolderPickerOverlayDTD;
  53. ]>
  54.  
  55. <bindings   id="filterBindings"
  56.             xmlns="http://www.mozilla.org/xbl"
  57.             xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  58.             xmlns:nc="http://home.netscape.com/NC-rdf#"
  59.             xmlns:xbl="http://www.mozilla.org/xbl">
  60.  
  61.   <binding id="ruleactiontype-menulist">
  62.     <content>
  63.       <xul:menulist class="ruleaction-type">
  64.           <xul:menupopup>
  65.             <xul:menuitem label="&moveMessage.label;" value="movemessage" enablefornews="false"/>
  66.             <xul:menuitem label="©Message.label;" value="copymessage"/>
  67.             <xul:menuseparator enablefornews="false"/>
  68.             <xul:menuitem label="&forwardTo.label;" value="forwardmessage" enablefornews="false"/>
  69.             <xul:menuitem label="&replyWithTemplate.label;" value="replytomessage" enablefornews="false"/>         
  70.             <xul:menuseparator/>
  71.             <xul:menuitem label="&markMessageRead.label;" value="markasread"/>
  72.             <xul:menuitem label="&markMessageFlagged.label;" value="markasflagged"/>
  73.             <xul:menuitem label="&labelMessage.label;" value="labelmessageas"/>
  74.             <xul:menuitem label="&setPriority.label;"  value="setpriorityto"/>
  75.             <xul:menuitem label="&setJunkScore.label;" value="setjunkscore" enablefornews="false"/>
  76.             <xul:menuseparator enableforpop3="true"/>
  77.             <xul:menuitem label="&deleteMessage.label;" value="deletemessage"/>
  78.             <xul:menuitem label="&deleteFromPOP.label;" value="deletefrompopserver" enableforpop3="true"/>
  79.             <xul:menuitem label="&fetchFromPOP.label;"  value="fetchfrompopserver" enableforpop3="true"/>
  80.             <xul:menuseparator enablefornews="true"/>
  81.             <xul:menuitem label="&ignoreThread.label;" value="ignorethread" enablefornews="true"/>
  82.             <xul:menuitem label="&watchThread.label;"  value="watchthread" enablefornews="true"/>
  83.           </xul:menupopup>
  84.       </xul:menulist>
  85.     </content>
  86.  
  87.     <implementation>
  88.       <constructor>
  89.         <![CDATA[
  90.           this.hideInvalidActions();
  91.           // differentiate between creating a new, next available action,
  92.           // and creating a row which will be initialized with an action
  93.           if (!this.parentNode.hasAttribute('initialActionIndex')) 
  94.           {        
  95.             var unavailableActions = this.usedActionsList();
  96.             // select the first one that's not in the list
  97.             var menuItems = this.menupopup.getElementsByTagName('menuitem');
  98.             for (var index = 0; index < menuItems.length; index++)
  99.             {
  100.               var menu = menuItems[index];
  101.               if (!(menu.value in unavailableActions) && !menu.hidden)
  102.               {
  103.                 this.menulist.value = menu.value;
  104.                 this.parentNode.setAttribute('value', menu.value);
  105.                 break;
  106.               }
  107.             }
  108.           }
  109.           else
  110.           {
  111.             this.parentNode.mActionTypeInitialized = true; 
  112.             this.parentNode.clearInitialActionIndex();
  113.           }
  114.         ]]>
  115.       </constructor>
  116.  
  117.       <field name="menupopup">document.getAnonymousNodes(this)[0].menupopup</field>
  118.       <field name="menulist">document.getAnonymousNodes(this)[0]</field>
  119.  
  120.       <method name="hideInvalidActions">
  121.         <body>
  122.           <![CDATA[
  123.              var scope = getScopeFromFilterList(gFilterList);
  124.  
  125.             // walk through the list of filter actions and hide any actions which aren't valid
  126.             // for our given scope (news, imap, pop, etc)
  127.             var elements, i;
  128.  
  129.             // disable / enable all elements in the "filteractionlist"
  130.             // based on the scope and the "enablefornews" attribute
  131.             elements = this.menupopup.getElementsByAttribute("enablefornews", "true");
  132.             for (i = 0; i < elements.length; i++) 
  133.               elements[i].hidden = scope != Components.interfaces.nsMsgSearchScope.newsFilter;
  134.  
  135.             elements = this.menupopup.getElementsByAttribute("enablefornews", "false");
  136.             for (i = 0; i < elements.length; i++) 
  137.               elements[i].hidden = scope == Components.interfaces.nsMsgSearchScope.newsFilter;
  138.  
  139.             elements = this.menupopup.getElementsByAttribute("enableforpop3", "true");
  140.             for (i = 0; i < elements.length; i++)
  141.               elements[i].hidden = scope != Components.interfaces.nsMsgSearchScope.offlineMailFilter;
  142.           ]]>
  143.         </body>
  144.       </method>
  145.  
  146.       <method name="numVisibleActions">
  147.         <body>
  148.           <![CDATA[
  149.             var numVisibleActions = 0;
  150.             var menuItems = this.menupopup.getElementsByTagName('menuitem');
  151.             // only count the items that are visible
  152.             for (var index = 0; index < menuItems.length; index++)
  153.               if (!menuItems[index].hidden)
  154.                 numVisibleActions++;
  155.             return numVisibleActions;
  156.           ]]>
  157.         </body>       
  158.       </method>
  159.       
  160.       <!-- returns a hash containing all of the filter actions which are currently being used by other filteractionrows -->
  161.       <method name="usedActionsList">
  162.         <body>
  163.           <![CDATA[
  164.             var usedActions = {};
  165.             var currentFilterActionRow = this.parentNode;
  166.             var listBox = currentFilterActionRow.mListBox; // need to account for the list item
  167.             // now iterate over each list item in the list box
  168.             for (var index = 0; index < listBox.getRowCount(); index++)
  169.             {
  170.               var filterActionRow = listBox.getItemAtIndex(index);
  171.               if (filterActionRow != currentFilterActionRow)
  172.                 usedActions[filterActionRow.getAttribute('value')] = true;
  173.             }
  174.             return usedActions;
  175.           ]]>
  176.         </body>       
  177.       </method>
  178.     </implementation>
  179.  
  180.     <handlers>
  181.       <handler event="command">
  182.         <![CDATA[
  183.           this.parentNode.setAttribute('value', this.menulist.value);
  184.         ]]>
  185.       </handler>
  186.  
  187.       <handler event="popupshowing">
  188.         <![CDATA[
  189.           var unavailableActions = this.usedActionsList();
  190.           var menuItems = this.menupopup.getElementsByTagName('menuitem');
  191.           for (var index = 0; index < menuItems.length; index++)
  192.           {
  193.             var menu = menuItems[index];
  194.             menu.setAttribute('disabled', menu.value in unavailableActions);
  195.           }   
  196.         ]]>
  197.       </handler>
  198.     </handlers>
  199.   </binding>
  200.  
  201.   <binding id="ruleaction">
  202.     <content allowevents="true">
  203.       <xul:listcell class="ruleactiontype"/>
  204.       <xul:listcell class="ruleactiontarget" xbl:inherits="type=value"
  205.                     orient="vertical" align="start" pack="center"/>
  206.       <xul:listcell>
  207.         <xul:button class="small-button" label="+" onclick="this.parentNode.parentNode.addRow();"/>
  208.         <xul:button class="small-button" label="-" onclick="this.parentNode.parentNode.removeRow();" anonid="removeButton"/>
  209.       </xul:listcell>
  210.       <xul:listcell/>
  211.     </content>
  212.  
  213.     <implementation>
  214.       <field name="mListBox">this.parentNode</field>
  215.       <field name="mRemoveButton">document.getAnonymousElementByAttribute(this, "anonid", "removeButton")</field>
  216.       <field name="mActionTypeInitialized">false</field>
  217.       <field name="mRuleActionTargetInitialized">false</field>
  218.  
  219.       <method name="clearInitialActionIndex">
  220.         <body>
  221.           <![CDATA[
  222.             // we should only remove the initialActionIndex after we have been told that
  223.             // both the rule action type and the rule action target hvae both been built since they both need 
  224.             // this piece of information. This complication arises because both of these child elements are getting
  225.             // bound asynchronously after the search row has been constructed
  226.             
  227.             if (this.mActionTypeInitialized && this.mRuleActionTargetInitialized)
  228.               this.removeAttribute('initialActionIndex');
  229.           ]]>
  230.         </body>
  231.       </method>
  232.  
  233.       <method name="initWithAction">
  234.         <parameter name="aFilterAction"/>
  235.         <body>
  236.           <![CDATA[
  237.             var filterActionStr = gFilterActionStrings[aFilterAction.type];
  238.             document.getAnonymousNodes(document.getAnonymousNodes(this)[0])[0].value = filterActionStr;
  239.             var actionTarget = document.getAnonymousNodes(this)[1];
  240.             switch (gFilterActionStrings[aFilterAction.type])
  241.             {
  242.               case "movemessage":
  243.               case "copymessage":
  244.                 gPicker = actionTarget;
  245.                 SetFolderPickerElement(aFilterAction.targetFolderUri, actionTarget.menulist);
  246.                 break;
  247.               case "replytomessage":
  248.               case "forwardmessage":
  249.                 document.getAnonymousNodes(actionTarget)[0].value = aFilterAction.strValue; 
  250.                 break;
  251.               case "labelmessageas":
  252.                 document.getAnonymousNodes(actionTarget)[0].value = aFilterAction.label;
  253.                 break;
  254.               case "setpriorityto":
  255.                 document.getAnonymousNodes(actionTarget)[0].value = aFilterAction.priority;
  256.                 break;
  257.               case "setjunkscore":
  258.                 document.getAnonymousNodes(actionTarget)[0].value = aFilterAction.junkScore;
  259.                 break;
  260.               default:
  261.                 break;
  262.             }
  263.  
  264.             this.mRuleActionTargetInitialized = true; 
  265.             this.clearInitialActionIndex();
  266.           ]]>
  267.         </body>
  268.       </method>
  269.  
  270.       <method name="validateAction">
  271.         <body>
  272.           <![CDATA[
  273.             // returns true if this row represents a valid filter action and false otherwise.
  274.             // This routine also prompts the user.
  275.             var filterActionString = this.getAttribute('value');
  276.             var actionTarget = document.getAnonymousNodes(this)[1];
  277.             var errorString;
  278.  
  279.             switch (filterActionString)
  280.             {
  281.               case "movemessage":
  282.               case "copymessage":
  283.                 var msgFolder = actionTarget.uri ? GetMsgFolderFromUri(actionTarget.uri) : null;
  284.                 if (!msgFolder || !msgFolder.canFileMessages) 
  285.                   errorString = "mustSelectFolder";
  286.                 break;
  287.               case "forwardmessage":
  288.                 if (document.getAnonymousNodes(actionTarget)[0].value.length < 3 || 
  289.                     document.getAnonymousNodes(actionTarget)[0].value.indexOf('@') < 2)
  290.                   errorString = "enterValidEmailAddress";
  291.                 break;
  292.               case "replytomessage":
  293.                 if (!document.getAnonymousNodes(actionTarget)[0].selectedItem)
  294.                    errorString = "pickTemplateToReplyWith";
  295.                 break;
  296.               default:
  297.                 break;
  298.             }
  299.  
  300.             if (errorString && gPromptService)
  301.               gPromptService.alert(window, null, gFilterBundle.getString(errorString));
  302.               
  303.             return !errorString;              
  304.           ]]>
  305.         </body>
  306.       </method>
  307.  
  308.       <method name="saveToFilter">
  309.         <parameter name="aFilter"/>
  310.         <body>
  311.           <![CDATA[
  312.             // create a new filter action, fill it in, and then append it to the filter
  313.             var filterAction = aFilter.createAction();
  314.             var filterActionString = this.getAttribute('value');
  315.             filterAction.type = gFilterActionStrings.indexOf(filterActionString);
  316.             var actionTarget = document.getAnonymousNodes(this)[1];
  317.  
  318.             switch (filterActionString)
  319.             {
  320.               case "labelmessageas":              
  321.                 filterAction.label = document.getAnonymousNodes(actionTarget)[0].getAttribute("value");
  322.                 break;
  323.               case "setpriorityto":
  324.                 filterAction.priority = document.getAnonymousNodes(actionTarget)[0].getAttribute("value");   
  325.                 break;
  326.               case "movemessage":
  327.               case "copymessage":
  328.                 filterAction.targetFolderUri = actionTarget.uri;
  329.                 break;
  330.               case "setjunkscore":
  331.                 filterAction.junkScore = document.getAnonymousNodes(actionTarget)[0].value;    
  332.                 break;
  333.               case "replytomessage":
  334.               case "forwardmessage":
  335.                 filterAction.strValue = document.getAnonymousNodes(actionTarget)[0].value; 
  336.                 break;
  337.               default:
  338.                 break;
  339.             }
  340.             aFilter.appendAction(filterAction);
  341.           ]]>
  342.         </body>
  343.       </method>
  344.  
  345.       <method name="addRow">
  346.         <body>
  347.           <![CDATA[
  348.             if (this.mListBox.getRowCount() < document.getAnonymousNodes(this)[0].numVisibleActions())
  349.             {             
  350.               var listItem = document.createElement('listitem');
  351.               listItem.className = 'ruleaction';             
  352.               this.mListBox.insertBefore(listItem, this.nextSibling);
  353.               this.mListBox.ensureElementIsVisible(listItem);
  354.  
  355.               // make sure the first remove button is enabled
  356.               this.mListBox.getItemAtIndex(0).mRemoveButton.disabled = false;
  357.             }
  358.           ]]>
  359.         </body>
  360.       </method>
  361.  
  362.       <method name="removeRow">
  363.         <body>
  364.           <![CDATA[
  365.             if (this.mListBox.getRowCount() > 1)
  366.               this.mListBox.removeChild(this);
  367.             // if we only have one row left, then disable the remove button for that row
  368.             this.mListBox.getItemAtIndex(0).mRemoveButton.disabled = this.mListBox.getRowCount() == 1;
  369.           ]]>
  370.         </body>
  371.       </method>
  372.     </implementation>
  373.   </binding>
  374.  
  375.   <binding id="ruleactiontarget-base">
  376.     <implementation>
  377.       <constructor>
  378.         <![CDATA[                    
  379.           if (this.parentNode.hasAttribute('initialActionIndex'))
  380.           {
  381.             var actionIndex = this.parentNode.getAttribute('initialActionIndex');
  382.             var filterAction = gFilter.actionList.QueryElementAt(actionIndex, Components.interfaces.nsIMsgRuleAction);
  383.             this.parentNode.initWithAction(filterAction);
  384.           }
  385.         ]]>
  386.       </constructor>
  387.     </implementation>
  388.   </binding>
  389.  
  390.   <binding id="ruleactiontarget-label" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  391.     <content>
  392.       <xul:menulist class="ruleactionitem">
  393.         <xul:menupopup>
  394.           <xul:menuitem value="0"/>
  395.           <xul:menuitem value="1"/>
  396.           <xul:menuitem value="2"/>
  397.           <xul:menuitem value="3"/>
  398.           <xul:menuitem value="4"/>
  399.           <xul:menuitem value="5"/>
  400.         </xul:menupopup>
  401.       </xul:menulist>
  402.     </content>
  403.  
  404.     <implementation>
  405.       <constructor>
  406.         <![CDATA[
  407.           var menuItems = document.getAnonymousNodes(this)[0].menupopup.childNodes;
  408.           var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch(null);
  409.  
  410.           for (var index = 0; index < menuItems.length; index++)
  411.           {
  412.             var menuEl = menuItems[index];
  413.             var prefString = prefBranch.getComplexValue("mailnews.labels.description." + menuEl.value,
  414.                                                         Components.interfaces.nsIPrefLocalizedString);
  415.             menuEl.setAttribute("label", prefString);
  416.           }
  417.           
  418.           // propagating a pre-existing hack to make the label get displayed correctly in the menulist
  419.           // now that we've changed the labels for each menu list. We need to use the current selectedIndex
  420.           // (if its defined) to handle the case where we were initialized with a filter action already.
  421.           var currentItem = document.getAnonymousNodes(this)[0].selectedItem;
  422.           document.getAnonymousNodes(this)[0].selectedItem = null;
  423.           document.getAnonymousNodes(this)[0].selectedItem = currentItem;
  424.         ]]>
  425.       </constructor>
  426.     </implementation>
  427.   </binding>
  428.  
  429.   <binding id="ruleactiontarget-priority" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  430.     <content>
  431.       <xul:menulist class="ruleactionitem">
  432.         <xul:menupopup>
  433.           <xul:menuitem value="6" label="&highestPriorityCmd.label;"/>
  434.           <xul:menuitem value="5" label="&highPriorityCmd.label;"/>
  435.           <xul:menuitem value="4" label="&normalPriorityCmd.label;"/>
  436.           <xul:menuitem value="3" label="&lowPriorityCmd.label;"/>
  437.           <xul:menuitem value="2" label="&lowestPriorityCmd.label;"/>
  438.         </xul:menupopup>
  439.       </xul:menulist>
  440.     </content>
  441.   </binding>
  442.  
  443.   <binding id="ruleactiontarget-junkscore" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  444.     <content>
  445.       <xul:menulist class="ruleactionitem">
  446.         <xul:menupopup>
  447.           <xul:menuitem value="100" label="&junk.label;"/>
  448.           <xul:menuitem value="0"   label="¬Junk.label;"/>
  449.         </xul:menupopup>
  450.       </xul:menulist>
  451.     </content>
  452.   </binding>
  453.  
  454.   <binding id="ruleactiontarget-replyto" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  455.     <content>
  456.       <xul:menulist class="ruleactionitem">
  457.         <xul:menupopup>
  458.         </xul:menupopup>
  459.       </xul:menulist>
  460.     </content>
  461.  
  462.     <implementation>
  463.       <constructor>
  464.         <![CDATA[
  465.             var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager);
  466.             var identity = accountManager.getFirstIdentityForServer(gFilterList.folder.server);
  467.             var rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
  468.             var resource = rdfService.GetResource(identity.stationeryFolder);
  469.             var msgFolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder);
  470.             var msgWindow = GetFilterEditorMsgWindow();
  471.             var msgDatabase = msgFolder.getMsgDatabase(msgWindow);
  472.             var enumerator = msgDatabase.EnumerateMessages();
  473.             var templateListPopup = document.getAnonymousNodes(this)[0].menupopup;
  474.  
  475.             if ( enumerator )
  476.             {
  477.               while (enumerator.hasMoreElements())
  478.               {
  479.                 var header = enumerator.getNext();
  480.                 if (header instanceof Components.interfaces.nsIMsgDBHdr)
  481.                 {
  482.                   var msgTemplateUri = msgFolder.URI + "?messageId=" + header.messageId + '&subject=' + header.subject;
  483.                   var newItem = document.getAnonymousNodes(this)[0].appendItem(header.subject, msgTemplateUri);
  484.                 }
  485.               }
  486.             }
  487.         ]]>
  488.       </constructor>      
  489.     </implementation>
  490.   </binding>
  491.  
  492.   <binding id="ruleactiontarget-forwardto" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  493.     <content>
  494.       <xul:textbox class="ruleactionitem"/>
  495.     </content>
  496.   </binding>
  497.  
  498.   <binding id="ruleactiontarget-folder" extends="chrome://messenger/content/searchWidgets.xml#ruleactiontarget-base">
  499.     <content>
  500.       <xul:menulist class="ruleactionitem">
  501.         <xul:menupopup class="folderTargetPopup" oncommand="SetFolderPickerElement(this.getAttribute('uri'), this.parentNode);"/>
  502.       </xul:menulist>
  503.     </content>
  504.  
  505.     <implementation>
  506.       
  507.       <constructor>
  508.         <![CDATA[
  509.           if (!this.uri)
  510.             SetFolderPickerElement(this.menulist.firstChild.tree.builderView.getResourceAtIndex(0).Value, this.menulist);
  511.         ]]>
  512.       </constructor>
  513.  
  514.       <property name="uri" readonly="true" onget="return document.getAnonymousNodes(this)[0].getAttribute('uri');"/>
  515.       <field name="menulist">document.getAnonymousNodes(this)[0]</field>
  516.     </implementation>
  517.   </binding>
  518. </bindings>
  519.